<template>
<div class="app-container calendar-list-container">
  <div class="filter-container">
    <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="订单号" v-model="listQuery.orderSn"> </el-input>
    <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="退单编号" v-model="listQuery.refundId"> </el-input>
    <el-select @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="退款方式" v-model="listQuery.refundWay"> 
      <el-option v-for="item in  refundWayOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
    </el-select>
    <el-select @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="退款状态" v-model="listQuery.refundStatus"> 
      <el-option v-for="item in  refundStatusOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
    </el-select>
    <el-date-picker class="filter-item" v-model="dateRange" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" placeholder="申请时间">
    </el-date-picker>
    <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
  </div>
  <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row style="width: 100%">
    <el-table-column align="center" label="订单号" min-width="10%"> <template scope="scope">
          <span>{{scope.row.orderSn}}</span>
        </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="商家"> <template scope="scope">
        <span>{{scope.row.shopName}}</span>
      </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="商品名称"> <template scope="scope">
        <span>{{scope.row.goodsName}}</span>
      </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="收货状态"> <template scope="scope">
            <span>{{scope.row.refundGoodsStatusName}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="商品数量"> <template scope="scope">
            <span>{{scope.row.goodsCount}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="退款金额"> <template scope="scope">
            <span>{{scope.row.userApplyAmount | currency('￥')}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="申请时间"> <template scope="scope">
            <span>{{scope.row.createTime}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="关闭时间"> <template scope="scope">
            <span>{{scope.row.closeTime}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="退款状态"> <template scope="scope">
            <span>{{scope.row.refundStatusName}}</span>
          </template> </el-table-column>
    <el-table-column align="center" label="操作" min-width="10%"> <template scope="scope">
        <el-button v-if="orderRefundManager_btn_detail && (scope.row.refundStatus === 50 || scope.row.refundStatus === 60)" size="small" type="success" @click="handleDetail(scope.row)">查看详情
        </el-button>
        <el-button v-if="orderRefundManager_btn_process && (scope.row.refundStatus !== 50 && scope.row.refundStatus !== 60)" size="small" type="warning" @click="handleDetail(scope.row)">处理退款
        </el-button>
      </template> </el-table-column>
  </el-table>
  
</div>
</template>

<script>
import {
  page,
  getObj,
  putObj
} from 'api/shop/order/refund/index';
import { mapGetters } from 'vuex';
import { getToken } from 'utils/auth';
import {getPicklist} from 'api/param/picklist/index';
import {currency} from '@/utils/index';
export default {
  name: 'allOrder',
  data() {
    return {
      rules: {
      },
      list: null,
      total: null,
      listLoading: true,
      sendListLoading:true,
      dateRange : null,
      listQuery: {
        pageNo: 1,
        pageSize: 20,
        orderSn: undefined,
        searchType:2,
        startTime : undefined,
        endTime : undefined,
        refundId:undefined,
        refundWay:undefined,
        refundStatus:undefined
      },
      orderRefundManager_btn_detail: false,
      orderRefundManager_btn_process: false,
      refundWayOptions:[
        {value:"1",label: '退货退款'},
        {value:"2",label: '仅退款'}
      ],
      refundStatusOptions:[
        {value:"1",label: '买家已经申请退款，等待卖家同意'},
        {value:"10",label: '卖家拒绝退款'},
        {value:"20",label: '卖家已经同意退货，等待买家退货'},
        {value:"30",label: '买家已经退货，等待卖家确认收货'},
        {value:"40",label: '卖家未收到货,拒绝退款'},
        {value:"50",label: '退款关闭'},
        {value:"60",label: '退款成功'}
      ],
      tableKey: 0
    }
  },
  created() {
    this.getList();
    this.orderRefundManager_btn_process = this.elements['orderRefundManager:btn_process'];
    this.orderRefundManager_btn_detail = this.elements['orderRefundManager:btn_detail'];
  },
  filters:{
    currency: currency
  },
  computed: {
    ...mapGetters([
      'elements'
    ])
  },
  methods: {
    getList() {
      this.listLoading = true;
      page(this.listQuery)
        .then(response => {
          this.list = response.data.rows;
          this.total = response.data.total;
          this.listLoading = false;
        })
    },
    handleFilter() {
      if(this.dateRange != null){
        this.listQuery.startTime = this.dateRange[0];
        this.listQuery.endTime = this.dateRange[1];
      }
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNo = val;
      this.getList();
    },
    handleDetail(row) {
       this.$router.push({path: '/shop/order/refundDetail',query: {id: row.refundId}});
    }
  }
}
</script>
<style scoped>

</style>